﻿Public Class Frm6UsuariosEditar
    Overloads Sub Show(ByVal p_ID As Integer, ByVal p_Usua As String, ByVal p_Contra As String, ByVal Frm6UsuariosMenu As Frm6UsuariosMenu)

        Me.lblIdRol.Text = p_ID
        Me.txtUsuario.Text = p_Usua
        Me.txtContrasenia.Text = p_Contra

        Me.Show()
    End Sub
    Public Function cargarRoles() As Boolean
        'Objeto Roles
        Dim accion As New rolesDAO
        Dim dato As String = lblIdRol.Text
        'Tabla temporal de roles
        Dim tabla As DataTable
        tabla = accion.mostrar
        'Comprobar si hay roles
        If tabla Is Nothing Then
            Return False
        Else

            'Trabajar con el control combox
            With cbxRol
                'No se permite modificar
                .DataSource = accion.mostrar
                'Fuentes de dtao
                .DropDownStyle = ComboBoxStyle.DropDownList
                'Campo a mostrar
                .DisplayMember = "Descripcion"
                'Clave principal
                .ValueMember = "ID_Rol"
                'No mostrar ningun rol
                .SelectedIndex = -1
            End With
            Return True
        End If
    End Function
    Private Sub Frm6UsuariosEditar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        cargarRoles()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Frm6UsuariosMenu.Show()
        Me.Close()

    End Sub

    Private Sub BtnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAceptar.Click
        Dim dato As New Usuarios
        Dim accion As New UsuariosDAO

        dato.pIdUsua = lblIdRol.Text
        dato.pUsua = txtUsuario.Text
        dato.pContra = txtContrasenia.Text
        dato.pIdRol = cbxRol.SelectedValue

        If accion.actualizar(dato) Then
            MessageBox.Show("Registro actualizado", "Modificar", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Else
            MessageBox.Show("No se puede modificar el registro, contacte al administrador", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End If
        Frm6UsuariosMenu.Show()
        Me.Close()
    End Sub
End Class